
import java.io.Serializable;
import java.util.Calendar;

public abstract class Message implements Serializable{

    private User user;
    private String date;
    private int friendID;
    protected String text;

    public Message() {
    }

    public Message(User u, int friend, String mText) {
        user = u;
        friendID = friend;
        text = mText;
        Calendar current = Calendar.getInstance();
        date = current.get(Calendar.MONTH) + " " + current.get(
                Calendar.DAY_OF_MONTH) + " " + current.get(Calendar.YEAR);
        user.addMessage(this);
    }

    public void setUser(User u) {
        user = u;
    }

    public User getUser() {
        return user;
    }

    public boolean setFriendID(int id) {
        if (user.hasFriend(id)) {
            friendID = id;
        }
        return user.hasFriend(id);
    }

    public int getFriendID() {
        return friendID;
    }

    public void setText(String t) {
        text = t;
    }

    public String getText() {
        return text;
    }

    public String getDate() {
        return date;
    }

    public abstract boolean encrypt();

    public abstract boolean decrypt();
    
    
    // update ----------------------------------------------
    @Override
    public String toString() {
        return "Friend ID: " + getFriendID() + " Date: " + getDate() +
                " Message: " + getText();
        
    }
}